// 2025/2/18: 首个版本

using System;
using ASEva.UIEto;
using Eto.Drawing;
using Eto.Forms;

namespace CommonSource
{
    class SingleSelect : DialogPanel
    {
        public SingleSelect(string title, string[] options, int defaultSelectIndex, Icon icon = null)
        {
            Icon = icon;
            Title = title;
            SetFixMode(400, 300, true);

            SelectedIndex = defaultSelectIndex;

            var layout = this.SetContentAsColumnLayout();

            var listBox = layout.AddControl(new ListBox(), true);
            foreach (var option in options) listBox.Items.Add(option);
            listBox.SelectedIndex = defaultSelectIndex;

            layout.AddButton("OK", false).Click += delegate
            {
                if (listBox.SelectedIndex >= 0) SelectedIndex = listBox.SelectedIndex;
                Close();
            };

            listBox.Activated += delegate
            {
                if (listBox.SelectedIndex >= 0) SelectedIndex = listBox.SelectedIndex;
                Close();
            };
        }

        public int SelectedIndex { get; private set; }
    }
}